package com.tvunetworks.center.user.model.param;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @program: tvucc-aggregator
 * @description: ChooseDeviceTypeParam
 * @author lebronchen
 * @create: 2019-06-18 11:06
 **/
@Data
@Accessors(chain = true)
public class ChooseDeviceTypeParam {

    protected boolean receiver;
    protected boolean pack;
    protected boolean anywhere;
    protected boolean gridPack;
    protected boolean gridSdi;
    protected boolean ext;
    protected boolean token;

    protected String appendSql;

    /**
     *
     * @return String
     */
    public String appendTypeSql(){
        StringBuffer buffer = new StringBuffer(" and ( 1<>1 ");
        if (receiver) {
            buffer.append(" or d.type = 'R' ");
        }
        if (pack && anywhere) {
            buffer.append(" or d.type = 'T' ");
        } else {
            if (pack) {
                buffer.append(" or (d.type = 'T' and (d.platform < 10 or d.platform > 14))");
            }
            if (anywhere) {
                buffer.append(" or (d.type = 'T' and d.platform >= 10 and d.platform <= 14)");
            }
        }
        if (gridPack && gridSdi) {
            buffer.append(" or d.type = 'X' ");
        } else {
            if (gridPack) {
                buffer.append(" or (d.type = 'X' and d.peer_id like '%0000000000000001')");
            }
            if (gridSdi) {
                buffer.append(" or (d.type = 'X' and d.peer_id like '%0000000000000002')");
            }
        }
        if (ext) {
            buffer.append(" or (d.type in ('Ext','YouTube','SMPTE2022'))");
        }
        buffer.append(" ) ");
        return buffer.toString();
    }
}
